<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

</body>
<script>
    function searchInsert(nums, target) {
        let index = 0;
        if (nums.indexOf(target, index) != -1) {
            index = nums.indexOf(target, index);
            return index;
        } else {
            nums.push(target);
            console.log(nums);
            nums.sort(function (a, b) {
                return a - b
            });
            console.log(nums);
            return nums.indexOf(target);
        }

    };
    let a = [3, 5, 7, 9, 10];
    let val = 8;
    console.log(searchInsert(a, val));
</script>

</html>